package com.chlitina.store.modules.cash.web;

import java.util.Date;

import com.chlitina.store.common.utils.DateUtils;
import com.chlitina.store.modules.cash.entity.StoreCardAll;
import com.chlitina.store.modules.cash.entity.StoreCardDuration;
import com.chlitina.store.modules.cash.entity.StoreCardProduct;
import com.chlitina.store.modules.cash.entity.StoreCardTimes;
import com.chlitina.store.modules.cash.model.CardCart;
import com.chlitina.store.modules.sys.entity.Store;

public class ConsumeUtils {
	public static String generateConsumeNumber(Store store, boolean member) {
		StringBuilder sb = new StringBuilder();
		if (member) {
			sb.append("HYXF");
		} else {
			sb.append("SKXF");
		}
		sb.append("-").append(getStoreID(store.getId()));
		sb.append("-").append(getDatetime());
		return sb.toString();
	}

	public static String generateCardNumberForCard(Object card) {
		StringBuilder sb = new StringBuilder();
		String prefix = null;
		if (card instanceof StoreCardAll) {
			prefix = "ZHK";
		} else if (card instanceof StoreCardProduct) {
			prefix = "CPK";
		} else if (card instanceof StoreCardDuration) {
			prefix = "SDK";
		} else if (card instanceof StoreCardTimes) {
			prefix = "JCK";
		}
		sb.append(prefix).append("-").append(getDatetime());
		return sb.toString();
	}
 
	public static String generateCardNumber(CardCart cart) {
		return generateCardNumberForCard( cart.getCard());
	}
	
	
	private static String getDatetime() {
		return DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
	}

	public static String getStoreID(long n) {
		StringBuilder sb = new StringBuilder(n + "");
		while (sb.length() < 3) {
			sb.insert(0, '0');
		}
		return sb.toString();
	}

	public static void main(String[] args) {
		System.err.println(getStoreID(1));
		System.err.println(getStoreID(1400));
	}
}
